import { getAction, deleteAction, putAction, postAction, httpAction, uploadAction } from '@/api/manage'
import Vue from 'vue'
import { UI_CACHE_DB_DICT_DATA } from "@/store/mutation-types"

const SERVICE_NAME = {
  JEECG_CLOUD_QUICK: 'jeecg-cloud-quick'
}
//角色管理
const addRole = (params) => postAction("/sys/role/add", params);
const editRole = (params) => putAction("/sys/role/edit", params);
const checkRoleCode = (params) => getAction("/sys/role/checkRoleCode", params);
const queryall = (params) => getAction("/sys/role/queryall", params);

//用户管理
const addUser = (params) => postAction("/sys/user/add", params);
const editUser = (params) => putAction("/sys/user/edit", params);
const queryUserRole = (params) => getAction("/sys/user/queryUserRole", params);
const queryUserRoleCodes = (params) => getAction("/sys/user/queryUserRoleCodes", params);
const getUserList = (params) => getAction("/sys/user/list", params);
const frozenBatch = (params) => putAction("/sys/user/frozenBatch", params);
//验证用户是否存在
const checkOnlyUser = (params) => getAction("/sys/user/checkOnlyUser", params);
//改变密码
const changePassword = (params) => putAction("/sys/user/changePassword", params);
//权限管理
const addPermission = (params) => postAction("/sys/permission/add", params);
const editPermission = (params) => putAction("/sys/permission/edit", params);
const getPermissionList = (params) => getAction("/sys/permission/list", params);
const getSystemMenuList = (params) => getAction("/sys/permission/getSystemMenuList", params);
const getSystemSubmenu = (params) => getAction("/sys/permission/getSystemSubmenu", params);
const getSystemSubmenuBatch = (params) => getAction('/sys/permission/getSystemSubmenuBatch', params)

const queryTreeList = (params) => getAction("/sys/permission/queryTreeList", params);
const queryTreeListForRole = (params) => getAction("/sys/role/queryTreeList", params);
const queryListAsync = (params) => getAction("/sys/permission/queryListAsync", params);
const queryRolePermission = (params) => getAction("/sys/permission/queryRolePermission", params);
const saveRolePermission = (params) => postAction("/sys/permission/saveRolePermission", params);
const queryPermissionsByUser = (params) => getAction("/sys/permission/getUserPermissionByToken", { lang: Vue.ls.get("lang", "CN") == 'CN' ? 'zh_CN' : 'en_GB' });
const loadAllRoleIds = (params) => getAction("/sys/permission/loadAllRoleIds", params);
const getPermissionRuleList = (params) => getAction("/sys/permission/getPermRuleListByPermId", params);
const queryPermissionRule = (params) => getAction("/sys/permission/queryPermissionRule", params);

// 部门管理
const queryDepartTreeList = (params) => getAction("/sys/sysDepart/queryTreeList", params);
const queryIdTree = (params) => getAction("/sys/sysDepart/queryIdTree", params);
const queryParentName = (params) => getAction("/sys/sysDepart/queryParentName", params);
const searchByKeywords = (params) => getAction("/sys/sysDepart/searchBy", params);
const deleteByDepartId = (params) => deleteAction("/sys/sysDepart/delete", params);

//二级部门管理
const queryDepartPermission = (params) => getAction("/sys/permission/queryDepartPermission", params);
const saveDepartPermission = (params) => postAction("/sys/permission/saveDepartPermission", params);
const queryTreeListForDeptRole = (params) => getAction("/sys/sysDepartPermission/queryTreeListForDeptRole", params);
const queryDeptRolePermission = (params) => getAction("/sys/sysDepartPermission/queryDeptRolePermission", params);
const saveDeptRolePermission = (params) => postAction("/sys/sysDepartPermission/saveDeptRolePermission", params);
const queryMyDepartTreeList = (params) => getAction("/sys/sysDepart/queryMyDeptTreeList", params);


//日志管理
const deleteLog = (params) => deleteAction("/sys/log/delete", params);
const deleteLogList = (params) => deleteAction("/sys/log/deleteBatch", params);

//数据字典
const addDict = (params) => postAction("/sys/dict/add", params);
const editDict = (params) => putAction("/sys/dict/edit", params);
const treeList = (params) => getAction("/sys/dict/treeList", params);
const addDictItem = (params) => postAction("/sys/dictItem/add", params);
const editDictItem = (params) => putAction("/sys/dictItem/edit", params);

//字典标签专用（通过code获取字典数组）
export const ajaxGetDictItems = (code, params) => getAction(`/sys/dict/getDictItems/${code}`, params);
//从缓存中获取字典配置
function getDictItemsFromCache(dictCode) {
  if (Vue.ls.get(UI_CACHE_DB_DICT_DATA) && Vue.ls.get(UI_CACHE_DB_DICT_DATA)[dictCode]) {
    let dictItems = Vue.ls.get(UI_CACHE_DB_DICT_DATA)[dictCode];
    // console.log("-----------getDictItemsFromCache----------dictCode=" + dictCode + "---- dictItems=", dictItems)
    return dictItems;
  }
}

//系统通告
const doReleaseData = (params) => getAction("/sys/annountCement/doReleaseData", params);
const doReovkeData = (params) => getAction("/sys/annountCement/doReovkeData", params);
//获取系统访问量
const getLoginfo = (params) => getAction("/sys/loginfo", params);
const getVisitInfo = (params) => getAction("/sys/visitInfo", params);
// 根据部门主键查询用户信息
const queryUserByDepId = (params) => getAction("/sys/user/queryUserByDepId", params);
// 重复校验
const duplicateCheck = (params) => getAction("/sys/duplicate/check", params);
// 加载分类字典
const loadCategoryData = (params) => getAction("/sys/category/loadAllData", params);
const checkRuleByCode = (params) => getAction('/sys/checkRule/checkByCode', params)
//加载我的通告信息
const getUserNoticeInfo = (params) => getAction("/sys/sysAnnouncementSend/getMyAnnouncementSend", params);
const getTransitURL = url => `/sys/common/transitRESTful?url=${encodeURIComponent(url)}`
const postPersionalInfo = (params) => postAction(`/talent/submitMyCondition`, params)
const getMyTeamInfo = (params) => postAction(`/talent/myTeam`, params)
const getEmpConditionByHr = (params) => postAction(`/talent/empConditionByHr`, params)
const getDeptTree = (workNo, lang) => getAction(`/sys/user/queryDeptTreeByRole?workNo=${workNo}&lang=${lang}`)
//搜索绩效潜能报表
const achievementslist = (params) => postAction("/talent/achievementslist", params);
//保存绩效潜能报表
const submitAchievementslist = (params) => postAction("/talent/submitAchievementslist", params);
const nineAchievementslist = (params) => postAction("/talent/nineInfo", params);
//hr 履历编辑提交
const hrSubmitEss = (params) => postAction("/talent/submitEmpConditionByHr", params);

const queryFirstDept = (params) => getAction('/sys/user/queryFirstDept', params)
const queryNextDept = (params) => getAction('/sys/user/queryNextDept', params)
const queryEmpList = (params) => postAction('/talent/queryEmpList', params)
const queryRoleSetup = (params) => postAction('/talent/queryRoleSetup', params)
const submitRoleSetup = (params) => postAction('/talent/submitRoleSetup', params)
const talentEchelonList = (params) => postAction('/talent/talentEchelonList', params)
const submitTalentEchelonList = (params) => postAction('/talent/submitTalentEchelonList', params)
const talentEchelonResultList = (params) => postAction('/talent/talentEchelonResultList', params)
const uploadProfileIcon = (params) => postAction('/talent/updatePictureUrl', params)
const queryPerInfoList = (params) => postAction('/talent/queryPerInfoList', params)
const getPersionalInfo = (workNo, lang, flag) => getAction(`/talent/myCondition?workNo=${workNo}&lang=${lang}&flag=${flag}`)
const BatchTalentEchelonList = (params) => postAction('/talent/batchTalentEchelonList', params)
const queryMyTeamMember = (workNo, lang) => getAction(`/talent/myTeamMember?workNo=${workNo}&lang=${lang}`)
const BatchAchievementslist = (params) => postAction('/talent/batchAchievementslist', params)
const DelTalentEchelon = (params) => postAction('/talent/delTalentEchelon', params)
const DelRoleSetup = (params) => postAction('/talent/delRoleSetup', params)

//流程
const getProcessModelData = (modelId) => getAction(`/activiti/models/modelData/${modelId}`)
const saveProcessModelData = (modelId, params) => uploadAction(`/activiti/activitiService/model/${modelId}/save`, params)
const NextAllDeptList = (params) => postAction('/talent/nextAllDeptList', params)
const ActZFormListAll = (params) => getAction("/activiti/actZForm/listAll", params);
const getHealthUploadData = (workNo, time) => getAction(`/${SERVICE_NAME.JEECG_CLOUD_QUICK}/frontpage/statisticsInfo?workNumber=${workNo}${time ? `&time=${time}` : ''}`)
const hrDeleteAll = (url,params) => deleteAction(url, {ids:''});
const hrDeleteDepartment = (url,params) => deleteAction(url, params);

const queryAllFirstDept = (params) => getAction('/sys/user/queryAllFirstDept', params)



const designQueryUserList = (params) => getAction('sys/design/jkDesignPersonal/queryUserList', params)
const designDeleteUser = (id) => deleteAction('/sys/design/jkDesignPersonal/delete', {id:id})
const addUserDesign = (params) => postAction('/sys/design/jkDesignPersonal/add', params)
const designQueryById = (params) => getAction(`/sys/design/jkDesignPersonal/getById/${params}`)
const editUserDesign = (params) => postAction('/sys/design/jkDesignPersonal/editpage', params)
const designStartUsing = (params) => postAction('/sys/design/jkDesignPersonal/start',  params)
const designStartView = (params) => getAction('/sys/design/jkDesignPersonal/startview',params)
const designComponents = (params) => getAction('/sys/design/jkDesignComponents/getComponents',params)
const designNotLeaf = (params) => getAction('/sys/design/jkDesignComponents/notleaf',params)

const executeSelect=(param) =>getAction('/sys/drag/inter/executeSelect',param)



// 中转HTTP请求
export const transitRESTful = {
  get: (url, parameter) => getAction(getTransitURL(url), parameter),
  post: (url, parameter) => postAction(getTransitURL(url), parameter),
  put: (url, parameter) => putAction(getTransitURL(url), parameter),
  http: (url, parameter) => httpAction(getTransitURL(url), parameter),
}

export {
  addRole,
  editRole,
  checkRoleCode,
  addUser,
  editUser,
  queryUserRole,
  queryUserRoleCodes,
  getUserList,
  queryall,
  frozenBatch,
  checkOnlyUser,
  changePassword,
  getPermissionList,
  addPermission,
  editPermission,
  queryTreeList,
  queryListAsync,
  queryRolePermission,
  saveRolePermission,
  queryPermissionsByUser,
  loadAllRoleIds,
  getPermissionRuleList,
  queryPermissionRule,
  queryDepartTreeList,
  queryIdTree,
  queryParentName,
  searchByKeywords,
  deleteByDepartId,
  deleteLog,
  deleteLogList,
  addDict,
  editDict,
  treeList,
  addDictItem,
  editDictItem,
  doReleaseData,
  doReovkeData,
  getLoginfo,
  getVisitInfo,
  queryUserByDepId,
  duplicateCheck,
  queryTreeListForRole,
  getSystemMenuList,
  getSystemSubmenu,
  getSystemSubmenuBatch,
  loadCategoryData,
  checkRuleByCode,
  queryDepartPermission,
  saveDepartPermission,
  queryTreeListForDeptRole,
  queryDeptRolePermission,
  saveDeptRolePermission,
  queryMyDepartTreeList,
  getUserNoticeInfo,
  getDictItemsFromCache,
  getPersionalInfo,
  postPersionalInfo,
  getMyTeamInfo,
  achievementslist,
  submitAchievementslist,
  getHealthUploadData,
  nineAchievementslist,
  getDeptTree,
  queryFirstDept,
  queryNextDept,
  queryEmpList,
  queryRoleSetup,
  submitRoleSetup,
  talentEchelonList,
  submitTalentEchelonList,
  talentEchelonResultList,
  uploadProfileIcon,
  queryPerInfoList,
  BatchTalentEchelonList,
  queryMyTeamMember,
  getEmpConditionByHr,
  BatchAchievementslist,
  DelTalentEchelon,
  DelRoleSetup,
  getProcessModelData,
  saveProcessModelData,
  hrSubmitEss,
  NextAllDeptList,
  ActZFormListAll,
  hrDeleteAll,
  hrDeleteDepartment,
  queryAllFirstDept,
  designQueryUserList,
  designDeleteUser,
  addUserDesign,
  designQueryById,
  editUserDesign,
  designStartUsing,
  designStartView,
  designComponents,
  designNotLeaf,
  executeSelect
}



